###############################################################################
##########  PACKAGE:  output_tables.pm
##########  PURPOSE:  Creates formatted text files of API data
###############################################################################
package output_tables;

use strict;
use warnings;
use Data::Dumper qw(Dumper);
use Date::Calc   qw(Add_Delta_Days);

use eve_const;
use api_utils;

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
	print_account_characters
	print_account_status
	print_accountbalance
	print_walletjournal
);

our $profile;
our $version;
our $currenttime;
our $cacheduntil;
our $charname;
our $corpname;
our $total;
our $accountkey;
our $cat;
our $f1;
our $f2;
our $f3;
our $f4;
our $f5;
our $f6;
our $f7;
our $f8;
our $f9;
our $f10;

###############################################################################
##### PRINT ACCOUNT CHARACTERS TABLE
##### INPUTS:  profiles, data (must be reference to %apidata hash)
##### OUTPUTS:  None
###############################################################################
sub print_account_characters {
	my $profiles = $_[0];
	$profile     = $profiles->{ACTIVE_PROFILE};
	my $filename = OUTPUT_DIR . "account_Characters_$profile.txt";
	my $data     = $_[1];
	$version     = $data->{$profile}{account}{characters}{version};
	$currenttime = $data->{$profile}{account}{characters}{currenttime};
	$cacheduntil = $data->{$profile}{account}{characters}{cacheduntil};
	$f1          = '';
	$f2          = '';
	$total       = 0;
	my $oldhandle;

	logger("--  BEGIN print_account_characters");
	print "OUTPUTTING ACCOUNT_CHARACTERS TABLE";
	open(OFILE, ">$filename") || fail("output_tables", "print_account_characters", "ERROR OPENING FILE $filename: $!");
	$oldhandle = select OFILE;
	$~ = "ACCOUNT_CHARACTERS_HEADER";
	write(OFILE) || &warn("output_tables", "print_account_characters", "ERROR WRITING FILE $filename: $!");
	$~ = "ACCOUNT_CHARACTERS";
	foreach $f1 (keys(%{$data->{$profile}{account}{characters}{characters}})) {
		$total++;
		$f2 = null2space($data->{$profile}{account}{characters}{characters}{$f1}{corporationname});
		write(OFILE) || &warn("output_tables", "print_account_characters", "ERROR WRITING FILE $filename: $!");
	}
	$~ = "ACCOUNT_CHARACTERS_FOOTER";
	write(OFILE) || &warn("output_tables", "print_account_characters", "ERROR WRITING FILE $filename: $!");
	select $oldhandle;
	close(OFILE) || &warn("output_tables", "print_account_characters", "ERROR CLOSING FILE $filename: $!");
	print "    DONE\n";
	logger("--  END print_account_characters");
}

###############################################################################
##### PRINT ACCOUNT STATUS TABLE
##### INPUTS:  profiles, data (must be reference to %apidata hash)
##### OUTPUTS:  None
###############################################################################
sub print_account_status {
	my $profiles = $_[0];
	$profile     = $profiles->{ACTIVE_PROFILE};
	my $data     = $_[1];
	my $filename = OUTPUT_DIR . "account_Status_$profile.txt";
	$version     = $data->{$profile}{account}{accountstatus}{version};
	$currenttime = $data->{$profile}{account}{accountstatus}{currenttime};
	$cacheduntil = $data->{$profile}{account}{accountstatus}{cacheduntil};
	$f1          = $data->{$profile}{account}{accountstatus}{logoncount};
	$f4          = $data->{$profile}{account}{accountstatus}{paiduntil};
	$f3          = $data->{$profile}{account}{accountstatus}{createdate};
	$f2          = $data->{$profile}{account}{accountstatus}{logonminutes};

	logger("--  BEGIN print_account_status");
	print "OUTPUTTING ACCOUNT_STATUS TABLE";
	open(OFILE, ">$filename") || &warn("output_tables", "print_account_status", "ERROR OPENING FILE $filename: $!");
	my $oldhandle = select(OFILE);
	$~ = "ACCOUNT_STATUS";
	write(OFILE) || &warn("output_tables", "print_account_status", "ERROR WRITING FILE $filename: $!");
	select($oldhandle);
	close(OFILE) || &warn("output_tables", "print_account_status", "ERROR CLOSING FILE $filename: $!");
	print "    DONE\n";
	logger("--  END print_account_status");
}

###############################################################################
##### PRINT ACCOUNT BALANCE TABLE
##### INPUTS:  profiles, category (must be 'char' or 'corp', charid,
#####          data (must be reference to %apidata hash)
##### OUTPUTS:  None
###############################################################################
sub print_accountbalance {
	my $profiles = $_[0];
	$profile     = $profiles->{ACTIVE_PROFILE};
	my $category = $_[1];
	my $charid   = $_[2];
	my $data     = $_[3];
	my $filename = OUTPUT_DIR . $category . "_AccountBalance_$profile-$charid.txt";
	$version     = $data->{$profile}{$charid}{$category}{accountbalance}{version};
	$currenttime = $data->{$profile}{$charid}{$category}{accountbalance}{currenttime};
	$cacheduntil = $data->{$profile}{$charid}{$category}{accountbalance}{cacheduntil};
	$charname    = $charid;  ##########  TEMP:  NEED TO ADD EVE_CHARACTERID API CALL
	$corpname    = 'TEMPORARY PLACEHOLDER';

	logger("--  BEGIN print_accountbalance");
	print "OUTPUTTING ACCOUNTBALANCE TABLE";
	open(OFILE, ">$filename") || &warn("output_tables", "print_accountbalance", "ERROR OPENING FILE $filename: $!");
	my $oldhandle = select(OFILE);
	$~ = "ACCOUNTBALANCE_HEADER";
	write(OFILE) || &warn("output_tables", "print_accountbalance", "ERROR WRITING FILE $filename: $!");
	$total = 0;
	$~ = "ACCOUNTBALANCE";
	foreach my $id (keys(%{$data->{$profile}{$charid}{$category}{accountbalance}{accountid}})) {
		$f1     = $data->{$profile}{$charid}{$category}{accountbalance}{accountid}{$id}{accountkey};
		$f2     = $data->{$profile}{$charid}{$category}{accountbalance}{accountid}{$id}{balance};
		$total += $f2;
		$f2     = stripdec(str2isk($f2));
		write(OFILE) || &warn("output_tables", "print_accountbalance", "ERROR WRITING FILE $filename: $!");
	}
	$~ = "ACCOUNTBALANCE_FOOTER";
	$total = stripdec(str2isk($total));
	write(OFILE) || &warn("output_tables", "print_accountbalance", "ERROR WRITING FILE $filename: $!");
	select($oldhandle);
	close(OFILE) || &warn("output_tables", "print_accountbalance", "ERROR CLOSING FILE $filename: $!");
	print "    DONE\n";
	logger("--  END print_accountbalance");
}

###############################################################################
##### PRINT WALLET JOURNAL TABLE
##### INPUTS:  profiles, category (must be 'char' or 'corp', charid, 
#####          data (must be reference to %apidata hash)
##### OUTPUTS:  None
###############################################################################
sub print_walletjournal {
	my $profiles = $_[0];
	$profile     = $profiles->{ACTIVE_PROFILE};
	my $category = $_[1];
	my $charid   = $_[2];
	my $data     = $_[3];
	my $fname    = OUTPUT_DIR . $category . "_WalletJournal_$profile-$charid-";
	$version     = $data->{$profile}{$charid}{$category}{walletjournal}{version};
	$currenttime = $data->{$profile}{$charid}{$category}{walletjournal}{currenttime};
	$cacheduntil = $data->{$profile}{$charid}{$category}{walletjournal}{cacheduntil};
	$charname    = $charid; ########## TEMP:  NEED TO ADD EVE_CHARACTERID API CALL
	$corpname    = 'TEMPORARY PLACEHOLDER';
	$cat         = uc($category);

	logger("--  BEGIN print_walletjournal");
	print "OUTPUTTING WALLETJOURNAL TABLES\n";
	
	foreach $accountkey (keys(%{$data->{$profile}{$charid}{$category}{walletjournal}{accountkey}})) {
		my $refids;
		my %dates;
		my @tmp;
		my $filename = $fname . "$accountkey.txt";
		open(OFILE, ">$filename") || &warn("output_tables", "print_wallet_journal", "ERROR OPENING FILE $filename: $!");
		my $oldhandle = select(OFILE);
		$~ = 'WALLETJOURNAL_HEADER';
		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		$~ = 'WALLETJOURNAL_LEDGER_HEADER';
		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		$~ = 'WALLETJOURNAL_LEDGER';
		my $entries    = 0;
		my $transacted = 0;
		foreach my $id (sort(keys(%{$data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}}))) {
			$f1 = substr($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{date}, 0, 10);
			$f2 = $data->{eve}{reftypes}{reftypeid}{$data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{reftypeid}};
			$f3 = $data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{amount};
			$f4 = $data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{balance};
			$refids->{$data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{reftypeid}}{refid}{$id} = $f3;
			$entries++;
			$transacted += $f3;
			$dates{$f1}{amount}  = $f3;
			$dates{$f1}{balance} = $f4;
			$f3 = str2isk(stripdec($f3));
			$f4 = str2isk(stripdec($f4));
			write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		}
		@tmp = sort(keys(%dates));
		$f1  = $tmp[0];
		$f2  = $tmp[-1];
		$f3  = $entries;
		$f4  = stripdec(str2isk($transacted));
		$f5  = stripdec(str2isk($dates{$f2}{balance}));
		$~   = 'WALLETJOURNAL_LEDGER_FOOTER';
		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		select($oldhandle);
		close(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR CLOSING FILE $filename: $!");

		$filename = $fname . "$accountkey-SUMMARY.txt";
		open(OFILE, ">$filename") || &warn("output_tables", "print_wallet_journal", "ERROR OPENING FILE $filename: $!");
		$oldhandle = select(OFILE);
		$~ = 'WALLETJOURNAL_HEADER';
		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		$~ = 'WALLETJOURNAL_TYPETOTALS_HEADER';
		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		$~ = 'WALLETJOURNAL_TYPETOTALS';
		$entries    = 0;
		$transacted = 0;
		foreach $f1 (sort(keys(%{$refids}))) {
			$f4 = 0;
			$f3 = 0;
			$f2 = $data->{eve}{reftypes}{reftypeid}{$f1};
			foreach my $id (keys(%{$refids->{$f1}{refid}})) {
				$f4 += $data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{amount};
				$f3++;
			}
			$transacted += $f4;
			$f4 = stripdec(str2isk($f4));
			write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
			$entries++;
		}
		$~ = 'WALLETJOURNAL_TYPETOTALS_FOOTER';
		$f1 = $entries;
		$f2 = stripdec(str2isk($transacted));
		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");

######  DATA ERRORS
#		$~ = 'WALLETJOURNAL_WEEKLYTOTALS_HEADER';
#		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
#		$~ = 'WALLETJOURNAL_WEEKLYTOTALS';
#		my $days;
#		foreach my $id (sort(keys(%{$data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}}))) {
#			my $date = substr($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{date}, 0, 10);
#			my $day  = substr($date, 8, 2);
#			$days->{$date}{refid}{$id} = $data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{amount};
#		}
#		data_dump('DAYS', $days);
#		my $startday   = 0;
#		my $startmonth = 0;
#		my $startyear  = 0;
#		my $endday     = 0;
#		my $endmonth   = 0;
#		my $endyear    = 0;
#		my $startdate  = '0';
#		my $enddate    = '0';
#		my $startbal   = 0;
#		my $endbal     = 0;
#		my $weeks;
#		foreach my $date (sort(keys(%{$days}))) {
#			if ($startdate eq '0') {
#				$date       =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
#				$startyear  = $1;
#				$startmonth = $2;
#				$startday   = $3;
#				$startdate  = $date;
#				($endyear, $endmonth, $endday) = Add_Delta_Days($startyear, $startmonth, $startday, 6);
#				$enddate = $endyear . '-' . padnum($endmonth) . '-' . padnum($endday);
#			} elsif ($date gt $enddate) {
#				$date       =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
#				$startyear  = $1;
#				$startmonth = $2;
#				$startday   = $3;
#				$startdate  = $date;
#				($endyear, $endmonth, $endday) = Add_Delta_Days($startyear, $startmonth, $startday, 6);
#				$enddate = $endyear . '-' . padnum($endmonth) . '-' . padnum($endday);
#			}
#			$f1 = $startdate;
#			$f2 = $enddate;
#			$f3 = 0;
#			@tmp = sort(keys(%{$days->{$date}{refid}}));
#			$startbal = $data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$tmp[0]}{balance};
#			$endbal   = $data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$tmp[-1]}{balance};
#			foreach my $id (sort(keys(%{$days->{$date}{refid}}))) {
#				$f3 += $data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{amount};
#			}
#			$weeks->{$f1}{END}  = $f2;
#			$weeks->{$f1}{DIFF} = $f3;
#			$weeks->{$f1}{BAL}  = $endbal;
#			$weeks->{$f1}{SBAL} = $startbal;
#		}
#		foreach $f1 (sort(keys(%{$weeks}))) {
#			$f2 = $weeks->{$f1}{END};
#			$f3 = $weeks->{$f1}{DIFF};
#			$f4 = $weeks->{$f1}{BAL};
#			$f5 = 0;
#			if ($f3 < 0) {
#				$f6 = ' ';
#				$f7 = 'LOSS';
#			} elsif ($f3 > 0) {
#				$f6 = 'GAIN';
#				$f7 = ' ';
#			}
#			$f3 = stripdec(str2isk(null2space($f3)));
#			$f4 = stripdec(str2isk(null2space($f4)));
#			$f5 = null2space($f5);
#			$f6 = null2space($f6);
#			$f7 = null2space($f7);
#			write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
#		}	
#		$~ = 'WALLETJOURNAL_WEEKLYTOTALS_FOOTER';
#		$f1 = '0';
#		$f2 = '2';
#		$f3 = '0';
#		$f4 = ' ';
#		$f5 = ' ';
#		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		select($oldhandle);
		close(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR CLOSING FILE $filename: $!");
	
		$filename = $fname . "$accountkey-DETAILS.txt";
		open(OFILE, ">$filename") || &warn("output_tables", "print_wallet_journal", "ERROR OPENING FILE $filename: $!");
		$oldhandle = select(OFILE);
		$~ = 'WALLETJOURNAL_HEADER';
		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		$~ = 'WALLETJOURNAL_COMPLETE_HEADER';
		write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		$~ = 'WALLETJOURNAL_COMPLETE';
		foreach my $id (sort(keys(%{$data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}}))) {
			$f1  = substr($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{date}, 0, 10);
			$f2  = null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{reftypeid});
			$f3  = stripdec(str2isk(null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{amount})));
			$f4  = stripdec(str2isk(null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{taxAmount})));
			$f5  = null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{ownerName1});
			$f6  = null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{ownerName2});
			$f7  = null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{taxReceiverID});
			$f8  = null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{argName1});
			$f9  = stripdec(str2isk(null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{balance})));
			$f10 = null2space($data->{$profile}{$charid}{$category}{walletjournal}{accountkey}{$accountkey}{entries}{$id}{reason});
			write(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR WRITING FILE $filename: $!");
		}
		select($oldhandle);
		close(OFILE) || &warn("output_tables", "print_wallet_journal", "ERROR CLOSING FILE $filename: $!");
	}
	print "DONE\n";
	logger("--  END print_walletjournals");
}
	
#########################################################################
##########     OUTPUT FORMATS     #######################################
#########################################################################

##### ACCOUNT_CHARACTERS FORMATS
format ACCOUNT_CHARACTERS_HEADER =
+-------------------------------------------------------------------------------+
| USER ID:  @<<<<<<  CHARACTER LIST                                             |
            $profile
+-------------------------------------------------------------------------------+
| VER: @<  CURRENT TIME: @<<<<<<<<<<<<<<<<<<  CACHED UNTIL: @<<<<<<<<<<<<<<<<<< | 
       $version,         $currenttime,                      $cacheduntil
+------------------------------------+------------------------------------------+
| CHARACTER NAME                     | CORPORATION NAME                         |
+------------------------------------+------------------------------------------+
.
format ACCOUNT_CHARACTERS =
| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
  $f1,                                 $f2
+------------------------------------+------------------------------------------+
.
format ACCOUNT_CHARACTERS_FOOTER =
| TOTAL CHARACTERS:  @<<<                                                       |
                     $total
+-------------------------------------------------------------------------------+
.

##### ACCOUNT_STATUS FORMATS
format ACCOUNT_STATUS =
+-------------------------------------------------------------------------------+
| USER ID:  @<<<<<<  ACCOUNT STATUS                                             |
            $profile
+-------------------------------------------------------------------------------+
| VER: @<  CURRENT TIME: @<<<<<<<<<<<<<<<<<<  CACHED UNTIL: @<<<<<<<<<<<<<<<<<< |
       $version,         $currenttime,                      $cacheduntil
+--------------------------------------+----------------------------------------+
| LOG ONS:  @<<<<<<<<<<<<<<<<<<        | MINUTES:     @<<<<<<<<<<<<<<<<<<       |
            $f1,                                      $f2
| CREATED:  @<<<<<<<<<<<<<<<<<<        | PAID UNTIL:  @<<<<<<<<<<<<<<<<<<       |
            $f3,                                      $f4
+--------------------------------------+----------------------------------------+
.

##### ACCOUNTBALANCE FORMATS
format ACCOUNTBALANCE_HEADER =
+-------------------------------------------------------------------------------+
| USER ID:  @<<<<<<  ACCOUNT BALANCES                                           |
            $profile
| CHARACTER NAME:    @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
                     $charname
| CORPORATION NAME:  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
                     $corpname
+-------------------------------------------------------------------------------+
| VER: @<  CURRENT TIME: @<<<<<<<<<<<<<<<<<<  CACHED UNTIL: @<<<<<<<<<<<<<<<<<< |
       $version,         $currenttime,                      $cacheduntil
+---------------------+---------------------------------------------------------+
.
format ACCOUNTBALANCE =
| ACCOUNT KEY:  @<<<  | BALANCE:  @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
                $f1,              $f2
.
format ACCOUNTBALANCE_FOOTER =
+---------------------+---------------------------------------------------------+
| TOTAL BALANCE:  @>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
                  $total
+-------------------------------------------------------------------------------+
.

##### WALLETJOURNAL FORMATS
format WALLETJOURNAL_HEADER =
+-------------------------------------------------------------------------------+
| USER ID:  @<<<<<<  @<<< WALLET JOURNAL  ACCOUNT KEY:  @<<<                    |
            $profile, $cat,                              $accountkey
| CHARACTER NAME:    @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
                     $charname
| CORPORATION NAME:  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
                     $corpname
+-------------------------------------------------------------------------------+
| VER: @<  CURRENT TIME: @<<<<<<<<<<<<<<<<<<  CACHED UNTIL: @<<<<<<<<<<<<<<<<<< |
       $version,         $currenttime,                      $cacheduntil
+-------------------------------------------------------------------------------+
.
format WALLETJOURNAL_LEDGER_HEADER =
+------------+------------------------+--------------------+--------------------+
| DATE       | TRANSACTION TYPE       | AMOUNT             | BALANCE            |
+------------+------------------------+--------------------+--------------------+
.
format WALLETJOURNAL_LEDGER =
| @<<<<<<<<< | @<<<<<<<<<<<<<<<<<<<<< | @>>>>>>>>>>>>>>>>> | @>>>>>>>>>>>>>>>>> |
  $f1,         $f2,                     $f3,                 $f4
.
format WALLETJOURNAL_LEDGER_FOOTER =
+------------+-----------------+--------------+----------------+----------------+
|  START DATE:     @<<<<<<<<<  |  END DATE:          @<<<<<<<<<                 |
                   $f1,                              $f2
|  TOTAL ENTRIES:  @<<<<<<<    |  TOTAL TRANSACTED:  @<<<<<<<<<<<<<<<<<<<<<<<<< |
                   $f3,                              $f4
|  TOTAL BALANCE:  @<<<<<<<<<<<<<<<<<<<<<<<<                                    |
                   $f5
+------------------------------+------------------------------------------------+
.
format WALLETJOURNAL_TYPETOTALS_HEADER =
+-------+---------------------------------------+---------+---------------------+
| REFID | REF NAME                              | ENTRIES | TOTAL               |
+-------+---------------------------------------+---------+---------------------+
.
format WALLETJOURNAL_TYPETOTALS =
| @<<<< | @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | @>>>>>> | @>>>>>>>>>>>>>>>>>> |
  $f1,    $f2,                                         $f3,      $f4
.
format WALLETJOURNAL_TYPETOTALS_FOOTER =
+-------+-------------------------+-------------+---------+---------------------+
| TOTAL TRANSACTION TYPES:  @<<<  |  AMOUNT TRANSACTED:  @>>>>>>>>>>>>>>>>>>>>> |
                            $f1,                         $f2
+---------------------------------+---------------------------------------------+
.
format WALLETJOURNAL_WEEKLYTOTALS_HEADER =
+------------+------------+----------------+----------------+-------+-----------+
| FROM       | TO         | DIFFERENCE     | BALANCE        | PCT   | P/L       |
+------------+------------+----------------+----------------+-------+-----------+
.
format WALLETJOURNAL_WEEKLYTOTALS =
| @<<<<<<<<< | @<<<<<<<<< | @>>>>>>>>>>>>> | @>>>>>>>>>>>>> | @<<<< | @<<< @<<< |
  $f1,         $f2,         $f3,             $f4,             $f5,    $f6, $f7
.
format WALLETJOURNAL_WEEKLYTOTALS_FOOTER =
+------------+------------+----------------+-------+--------+-------+-----------+
| DIFF:   @<<<<<<<<<<<<<  | BAL:   @<<<<<<<<<<<<<  | PCT: @<<<<     | @<<< @<<< |
          $f1,                     $f2,                   $f3,        $f4, $f5
+-------------------------+------------------------+----------------+-----------+
.
format WALLETJOURNAL_COMPLETE_HEADER =
+------------+-------+------------------+------------+------------------+------------------+----------+----------+------------------+
| DATE       | TYPE  | AMOUNT           | TAX AMOUNT | OWNER NAME1      | OWNER NAME2      | TAX REC  | ARGNAME1 | BALANCE          |
| REASON                                                                                                                            |
+-----------------------------------------------------------------------------------------------------------------------------------+
.
format WALLETJOURNAL_COMPLETE =
| @<<<<<<<<< | @<<<< | @>>>>>>>>>>>>>>> | @>>>>>>>>> | @<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<< | @<<<<<<< | @<<<<<<< | @>>>>>>>>>>>>>>> |
  $f1,         $f2,    $f3,               $f4,         $f5,               $f6,               $f7,       $f8,       $f9
| ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
  $f10
| ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |~~
  $f10
+-----------------------------------------------------------------------------------------------------------------------------------+
.

1;
